package com.bestom.smartwatch.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bestom.smartwatch.R;
import com.bestom.smartwatch.util.LogUtil;

import java.util.ArrayList;
import java.util.HashMap;
import butterknife.BindView;
import butterknife.ButterKnife;

public class AutoPollAdapter extends RecyclerView.Adapter<AutoPollAdapter.ViewHolder>{
    /**
     * 事件回调监听
     */
    private OnItemClickListener onItemClickListener;

    private Context context;

    private ArrayList<HashMap<String, String>> listBeans;

    public AutoPollAdapter(Context context, ArrayList<HashMap<String, String>> listBeans){
        this.context=context;

        this.listBeans=listBeans;

    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
        // 实例化展示的view
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.item_auto_poll,parent,false);
        // 实例化viewHolder
        return new ViewHolder(view);

    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        if (position >= listBeans.size()) return;
        HashMap<String, String> map = listBeans.get(position);
        holder.itemName.setText(map.get("itemName"));
        holder.itemStep.setText(map.get("itemStep"));
        holder.itemTemp.setText(map.get("itemTemp"));
        holder.itemTime.setText(map.get("itemTime"));
    }



    @Override
    public int getItemCount(){
        //主要在这，实现无线轮播效果
        return Integer.MAX_VALUE;
    }


    public static class ViewHolder extends RecyclerView.ViewHolder{
        @BindView(R.id.item_name)
        TextView itemName;
        @BindView(R.id.item_time)
        TextView itemTime;
        @BindView(R.id.item_step)
        TextView itemStep;
        @BindView(R.id.item_temp)
        TextView itemTemp;

        public ViewHolder(View itemView){
            super(itemView);

            ButterKnife.bind(this,itemView);

        }

    }

    /**
     * 设置回调监听
     *
     * @param listener

     */

    public void setOnItemClickListener(OnItemClickListener listener){
        this.onItemClickListener=listener;

    }

    public interface OnItemClickListener {
        void onItemClick(int position);

    }


}
